<template>
  <div class="history">
    <div class="main1">
      <div class="nav">
        <div class="nav-text" v-if="data">
          <p v-for="s in data1" :key="s.type" @click="current = s.type" :class="{ active: current == s.type }">{{ s.name
          }}</p>
          <span>{{ current }}</span>
        </div>
        <div class="swiper">
          <!-- 轮播图 -->
          <swiper ref="swiper" @mouseover.native="stopSwiper" @mouseout.native="startSwiper" class="swiper"
            :options="swiperOptions">
            <swiper-slide class="lunbo">
              <img src="../../public/img/hero/h1_hero1.jpg" alt="" />
            </swiper-slide>
            <swiper-slide class="lunbo">
              <img src="../../public/img/hero/h1_hero2.jpg" alt="" />
            </swiper-slide>
            <swiper-slide class="lunbo">
              <img src="../../public/img/hero/h1_hero3.jpg" alt="" />
            </swiper-slide>
            <swiper-slide class="lunbo">
              <img src="../../public/img/hero/h2_hero1.jpg" alt="" />
            </swiper-slide>
            <swiper-slide class="lunbo">
              <img src="../../public/img/hero/h2_hero2.jpg" alt="" />
            </swiper-slide>
            <!-- 分页器 -->
            <div class="swiper-pagination" slot="pagination"></div>
          </swiper>
        </div>
      </div>
      <div class="popr" v-if="data">
        <div class="box">
          <h2>历史新书</h2>
          <div class="bianli">
            <allview v-for="s in data.result" :key="s.id" :p="s"/>
          </div>
          <div class="page">
            <button @click="getData(data.page += 1)">上一页</button>
            <span v-for="(i, b) in 3" :key="b">{{ i }}</span>
            <button @click="getData(data.page += 1)">下一页</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>


<script>
import Allview from '../components/Allview.vue';

export default {


  components: { Allview },
  // props:['p'],
  mounted() {
    this.getData();
    // console.log(this.data.result.classid)
  },
  data() {
    return {
      data: null,
      current: 3,
      data1: [
        {
          name: "首页",
          type: 1
        },
        {
          name: "历史",
          type: 2
        }, {
          name: "党史",
          type: 3
        },
        {
          name: "恐怖",
          type: 4
        },
        {
          name: "自传",
          type: 5
        },
        {
          name: "专业",
          type: 6
        },
        {
          name: "科幻",
          type: 7
        }],
      swiperOptions: {
        //效果特效
        effect: "cors",
        //循环
        loop: true,

        //自动滚动
        // autoplay: {
        //   delay: 1000,
        //   disableOnInteraction: false,
        // },
      },

    }
  },


  props: { classid: { default: '' } },
  watch: {
    classid(to, from) {
      console.log('to:', to)
      console.log('to:', to)

    },
    current(to, from) {
      console.log('to', to)
      this.getData()
      if (this.current == 1) {
        this.$router.push('/')
        return
      }
    }
  },
  methods: {
    // toall() {
    //   this.current = s.type
    // },
    // nextpage(page) {
    //   console.log(this.data.page)
    //   page=this.data.result.page++;
    //   console.log(page)
    // },
    stopSwiper() {
      this.$refs.swiper.$swiper.autoplay.stop();
    },
    startSwiper() {
      this.$refs.swiper.$swiper.autoplay.start();
    },
    getData(page = 1) {
      const url = `aill/select?classid=${this.current}&page=${page}`
      this.axios.get(url).then((res) => {
        console.log(res.data)
        console.log(page)
        console.log(this.current)
        this.data = res.data
      })
    },
   
  }
};
</script>

<style lang="scss" scoped>
.history {
  background-color: rgb(252, 237, 237);
  width: 100%;
  height: 100%;
}

.main1 {
  background-color: rgb(252, 237, 237);
  height: 1660px;

  // 最畅销书籍
  .popr {
    background-color: rgb(252, 237, 237);

    height: 570px;

    // h2 {
    //   font-size: 20px;
    //   font-weight: 500;
    //   margin-bottom: 60px;
    // }
    .box {
      width: 1200px;
      height: 1000px;
      margin: auto;
      background-color: rgb(252, 237, 237);
      // background-color: aquamarine;

      // margin-left: 20px;


      h2 {
        height: 50px;
        // background-color: blueviolet;
        width: 100%;
        text-align: left;
        line-height: 50px;
        font-size: 25px;
        letter-spacing: 2px;
        border-bottom: 2px solid grey;
      }

      .bianli {
        width: 100%;
        height: 900px;
        // background-color: burlywood;
        display: flex;
        flex-wrap: wrap;
      }

      .page {
        margin-top: -20px;
        display: flex;
        justify-content: center;
        align-items: center;

        button {
          width: 80px;
          height: 50px;
        }

        span {
          display: inline-block;
          height: 50px;
          width: 50px;
          margin-left: 10px;
          margin-right: 10px;
          text-align: center;
          background-color: antiquewhite;
          line-height: 50px;
        }
      }
    }
  }

  .nav-text {
    margin: auto;
    background-color: aquamarine;
    height: 60px;
    width: 600px;
    display: flex;
    justify-content: space-between;
    align-items: center;

    p {
      font-size: 18px;
      width: 80px;
      height: 60px;
      line-height: 60px;
      // background-color: blueviolet;

      &active {
        // height: 60px;
        // width: 80px;
        background-color: red;
      }
    }
  }
}
</style>